//
//  XMCityView.m
//  XMJJ_zml
//
//  Created by 杨何华 on 2025/5/20.
//

#define CellIdentifier   @"XMCityCollectionViewCell"
#import "Masonry/Masonry.h"
#import "XMCitySelectView.h"
#import "XMCityCollectionViewCell.h"
@interface XMCitySelectView()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (strong,nonatomic)UICollectionView * cityView;
@end

@implementation XMCitySelectView
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initWithView];
    }
    return self;
}
- (void)initWithView
{
    
    UICollectionViewLayout * layout = [UICollectionViewLayout alloc];
    self.cityView = [[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:layout];
    [self.contentView addSubview:self.cityView];
    
    self.cityView.dataSource = self;
    self.cityView.delegate = self;
    [self.cityView registerClass:[XMCityCollectionViewCell class] forCellWithReuseIdentifier:CellIdentifier];
    [self.cityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.contentView).offset(5);
        make.left.and.right.equalTo(self.contentView).offset(5);
   }];

}
//
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    XMCityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    return cell;
}



#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    // 计算单个元素的尺寸
    return CGSizeMake(70, 30); // 假设九宫格为正方形
}

@end
